package com.itheima.servletcontext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class ServletContextDemo01 extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        Enumeration<String> names = context.getInitParameterNames();
        while (names.hasMoreElements()){
            String key = names.nextElement();
            String value = context.getInitParameter(key);
            System.out.println(key+"==="+value);
        }


        String servletContextName = context.getServletContextName();
        System.out.println("servletContextName:"+servletContextName);

        String contextPath = context.getContextPath();
        System.out.println("虚拟路径:"+contextPath);
        String realPath = context.getRealPath("/");
        System.out.println("项目被部署在了:"+realPath);
        System.out.println(context.getServerInfo());


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
